package com.citcc.api.controller;

import com.citcc.api.config.Authorization;
import com.citcc.business.bean.CdzAppUser;
import com.citcc.business.bean.vo.AmountDetailGetTypeVO;
import com.citcc.business.bean.vo.AmountDetailVO;
import com.citcc.business.service.CdzAmountDetailService;
import com.citcc.common.msg.Response;
import com.citcc.common.utils.ResponseUtil;
import com.citcc.common.utils.StringUtils;
import com.citcc.framework.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * Created by czh on 2019/5/17 14:52
 */
@Api(value = "金额明细", tags = "我的钱包")
@RestController
@RequestMapping("/amountDetail")
public class CdzAmountDetailController extends BaseController {

    @Autowired
    private CdzAmountDetailService amountDetailService;

    /**
     * 余额明细
     *
     * @param user
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页总条数", dataType = "Integer"),
            @ApiImplicitParam(name = "orderByColumn", value = "排序字段"),
            @ApiImplicitParam(name = "isAsc", value = "排序类型 DESC/ASC"),
            @ApiImplicitParam(name = "type", value = "操作类型 0-全部 1-充值 2-充电 3-提现 4-冻结", required = true)
    })
    @PostMapping("/v1/rechargeRecord")
    @ApiOperation(value = "余额明细", notes = "需要在header中加入Authorization。")
    public Response<AmountDetailVO> rechargeRecord(@ApiIgnore @Authorization CdzAppUser user, @RequestParam("type") String type) {
        if (StringUtils.isBlank(type)) return ResponseUtil.fail(null, "操作类型不能为空");
        startPage();
        return ResponseUtil.success(amountDetailService.rechargeRecord(user.getId(), type));
    }

    /**
     * 余额明细操作类型
     *
     * @return
     */
    @PostMapping("/v2/getType")
    @ApiOperation(value = "余额明细操作类型")
    public Response<List<AmountDetailGetTypeVO>> getType() {
        return ResponseUtil.success(amountDetailService.getType());
    }
}